#include "tim_app.h"

void Tim_set_duty(uint16_t duty)
{
    TIM2->CCR2 = (TIM2->ARR +1 )* (duty / 100.0f);
}

void Tim_set_freq(uint16_t freq)
{
    uint32_t Clock_freq = 1000000;

    uint32_t value = Clock_freq / freq - 1;

    TIM2->CCR2 = (value + 1) * (TIM2->CCR2 / TIM2->ARR);

    TIM2->ARR = value;

    TIM2->EGR = TIM_EGR_UG;
}


void tim_proc(void)
{

}

uint32_t ic_buffer[2][30];
uint32_t ic_value[2];
void tim_ic_proc(void)
{
    ic_value[0] = ic_value[1] = 0;
    for(int i=0; i<30; i++)
    {
        ic_value[0] += ic_buffer[0][i];
        ic_value[1] += ic_buffer[1][i];
    }
    ic_value[0] /= 30;
    ic_value[1] /= 30;

    ic_value[0] = 10000000.0f / ic_value[0];
    ic_value[1] = 10000000.0f / ic_value[1];
}